package cn.oveay.classdesign.service.impl;

import cn.oveay.classdesign.dao.UserDao;
import cn.oveay.classdesign.dao.impl.UserDaoImpl;
import cn.oveay.classdesign.service.UserService;
import cn.oveay.classdesign.bean.basebean.User;
import cn.oveay.classdesign.util.commons.Nanoflake;
import cn.oveay.classdesign.util.security.SHA;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    public List<User> findAll(){
        return userDao.findAll();
    }

    public void inseartUser(User user){
        user.setId(Nanoflake.getNanoflake());
        user.setOnline(User.OFFLINE);
        user.setPwd(SHA.SHA256Encoding(user.getPwd()));
        userDao.inseartUser(user);
    }

    public User findByName(String name){
        return userDao.findByName(name);
    }

    public void delete(String name){
        userDao.delete(name);
    }

    @Override
    public void updateUser(User user) {
        userDao.updateUser(user);
    }

    @Override
    public void trunOffOnlineToAllUser() {
        userDao.trunOffOnlineToAllUser();
    }

    @Override
    public User findById(String id) {
        return userDao.findById(id);
    }
}
